// 封装axios

import axios from 'axios'
import { Message } from 'element-ui'

// 1.创建axios实例
const request = axios.create({
    //接口
    baseURL: 'http://127.0.0.1:9001',
    // 超时时间 单位是ms
    timeout: 5000,
    headers: {
        "Access-Control-Allow-Origin": "*",
        "Content-Type": "application/json;charset=utf-8"
    }
 })

// 响应拦截器
request.interceptors.response.use(
    response => {
        // 未设置状态码则默认成功状态
        const code = response.data.code || 200;
        if(code === 200) {
            const res = response.data
            return res
        } else {
            return Promise.reject('error')
        }
    },
    error => {
        console.log('err' + error)
        return Promise.reject(error)
    }
)


 // 导出axios实例
export default request;